1. Field of the Invention
Embodiments of the present invention relate generally to application programming interface and processor interactions and more specifically to a method and system for overriding programmed state in a processing pipeline.
2. Description of the Related Art
Unless otherwise indicated herein, the approaches described in this section are not prior art to the claims in this application and are not admitted to be prior art by inclusion in this section.
Graphics APIs are used to specify state controls used by a processor to process data and produce images. Ideally, the various state controls are orthogonal and any possible setting of a particular state control is valid. Unfortunately, certain state control combinations are “illegal” since they can produce an undefined result or cause an error condition that hangs the processor when the particular state control combination is used to process data. Examples of some illegal combinations include enabling both logic operations and alpha blending, enabling dual-source blending when the color target format is not blendable, or setting the active render target layer number to a number that exceeds the number of available layers in the render target.
Conventionally, a variety of schemes have been used to handle illegal state control combinations. One scheme is to simply program the processor without regard to whether or not the state control combinations are legal or illegal, and have the processor detect and report any illegal state control combinations as errors and halt any processing. Unfortunately, most graphics APIs do not provide a mechanism for indicating these errors to a user, so there isn't an effective way to remedy the error and allow the processor to resume processing. Therefore, that scheme is not useful in a production system.
Another scheme is to have the processor detect and report any illegal state control combinations as errors and halt any processing until a device driver intervenes and programs a legal state control combination. The device driver is burdened with maintaining the state control settings that were programmed by the API in order to determine a legal state control setting during error handling. The tracking of the programmed state controls and error handling performed by the device driver requires complex code and reduces the system processing performance since the processor is halted during the error handling.
Another scheme is to have the device driver detect and correct illegal state control combinations before sending them to the processor. This also requires the device driver to maintain the state control settings that were programmed by the API. In addition, it burdens the device driver with tests to detect illegal state control combinations, and then with the task of overriding illegal state control settings with legal ones. The tracking of the programmed state controls, checking for illegal state combinations, and checking to see if state controls have become legal again, requires complex code and reduces the system processing performance because of the storage and testing overhead, even if no error conditions are actually present.
FIG. 1 is a simplified diagram of a prior art processing system 105 in which the device driver detects and corrects illegal state control combinations. Processing system 105 includes a device driver 110 that maintains a copy of the API programmed state as shadow state 120. An application program 140 provides data and program instructions that specify state controls defined by an API 130. Application program 140 calls a runtime component of API 130 that calls device driver 110 to translate the program instructions for execution by a processor 100. Device driver 110 determines if a particular state control combination is illegal, as defined by API 130, and replaces the illegal state control with a legal state control. Device driver 110 also preserves the desired state control that was provided by application program 140 by saving a copy of the API programmed state controls as shadow state 120. Shadow state 120 is used to detect illegal state control combinations and to determine legal state control settings during error handling.
As previously explained, the error detection, notification, and handling reduces the data processing throughput of processing system 105. In particular, device driver 110 includes complex code for performing the detection and error handling. Execution of this code for error condition detection, even when errors don't exist may also reduce the data processing throughput of processing system 105.
As the foregoing illustrates, a mechanism is needed to detect and correct API programmed state control error conditions without requiring a processor to halt while the error condition is remedied and without requiring the device driver to validate state combinations and to maintain shadow copies of overridden state.